import socket

# # 创建服务器的套接字实例
# server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#
# # 绑定ip 和端口
# SERVER_INFO = ("192.168.11.151", 60000)
# server_socket.bind(SERVER_INFO)
#
# # 侦听
# server_socket.listen()
#
# # 接收客户端连接
# client_socket, client_addr = server_socket.accept()
# print(f'{client_addr}成功连接')
#
# # 向客户端发送消息
# send_msg = input("请输入发送信息")
# send_bytes = send_msg.encode("gbk")
# client_socket.send(send_bytes)
#
# # 接收客户端信息
# recv_bytes = client_socket.recv(1024)
# recv_msg = recv_bytes.decode("gbk")
# print(f"收到消息", recv_msg)
#
# # 关闭客户端  关闭服务器
# server_socket.close()
# client_socket.close()


server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

SERVER_INFO = ("192.168.11.151", 60000)
server_socket.bind(SERVER_INFO)

server_socket.listen()

client_socket, client_addr = server_socket.accept()
print(f"{client_addr}成功连接")

seed_msg = input("请输入要发送的信息")
seed_bytes = seed_msg.encode("gbk")
client_socket.send(seed_bytes)
print(f"{seed_msg}成功发送")

recv_bytes = client_socket.recv(1024)
recv_msg = recv_bytes.decode("gbk")
print(f"成功接收{recv_msg}")

server_socket.close()
client_socket.close()
